home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / xdl.pro < prev    next >
Text File  |  1997-07-08  |  8KB  |  252 lines

  1. ; $Id: xdl.pro,v 1.6 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;    XDL
  8. ;
  9. ; PURPOSE:
  10. ;    Provide a graphical user interface to the DOC_LIBRARY user
  11. ;    library procedure.  XDL is different from the "?" command under
  12. ;    X windows in that every "user library" type routine in the IDL
  13. ;    distribution is displayed in a single list.  Also, any ".pro" files
  14. ;    in the current directory are scanned for documentation headers and
  15. ;    put into the list if they are documented.
  16. ;
  17. ; CATEGORY:
  18. ;    Help, documentation, widgets.
  19. ;
  20. ; CALLING SEQUENCE:
  21. ;    XDL [, Name]
  22. ;
  23. ; OPTIONAL INPUTS:
  24. ;    Name:    A scalar string that contains the name of the initial routine
  25. ;        for which help is desired.  This argument should be a scalar
  26. ;        string.
  27. ; KEYWORDS:
  28. ;    GROUP:    The widget ID of the widget that calls XDL.  When
  29. ;        this keyword is specified, a death of the caller results in a
  30. ;        death of XDL.
  31. ;
  32. ; OUTPUTS:
  33. ;    No explicit outputs.  A widget interface is used to allow reading
  34. ;    the help text.
  35. ;
  36. ; COMMON BLOCKS:
  37. ;    XDL_BLOCK - Internal to this module.
  38. ;
  39. ; RESTRICTIONS:
  40. ;    This routine does not support many of the keywords supported
  41. ;    by the DOC_LIBRARY procedure.
  42. ;
  43. ;    This routine uses DOC_LIBRARY to do much of the actual work
  44. ;    of finding the documentation text.  The alternative would be
  45. ;    to duplicate much of DOC_LIBRARY, which is undesirable.  However,
  46. ;    the use of DOC_LIBRARY leads to messages sometimes being sent
  47. ;    to the terminal.
  48. ;
  49. ; MODIFICATION HISTORY:
  50. ;    5 January 1991, AB
  51. ;       9 January 1992, ACY for Jim Pendleton, NWU; handle invalid library
  52. ;    28 April 1992, AB, Modified to only search !PATH for routine names
  53. ;        on the first invocation. The names are saved in the XDL_BLOCK
  54. ;        common block, so that following invocations start much faster.
  55. ;    15 September 1991, ACY, Correct ls command for IRIX
  56. ;    20 February 1993 Updated for VMS directory Library W. Landsman
  57. ;    27 May 1993, TAC,  Send invalid OS message for Windows and Macintosh
  58. ;    25 June 1993, AB, Fixed error in call to DL_VMS, and shortened the
  59. ;        list and text widgets slightly to accomodate larger fonts.
  60. ;    1 July 1995, AB, Replaced use of XANNOUNCE with WIDGET_MESSAGE and
  61. ;        improved status label sizing.
  62. ;-
  63.  
  64.  
  65.  
  66.  
  67. function xdl_list, parent
  68. ; Returns a list widget containing the names of all routines in !PATH.
  69. ; The array of names are saved in the XDL_BLOCK.
  70.   common XDL_BLOCK, NAMES, N_NAMES, text_w, status_w
  71.  
  72.   if (n_elements(names) eq 0) then begin
  73.     WIDGET_CONTROL, /HOURGLASS
  74.     path = strcompress(!PATH, /remove_all)
  75.     is_vms = !version.os eq 'vms'
  76.     if (is_vms) then SEP=',' else SEP=':'
  77.     N_NAMES = 0
  78.     while (strlen(path) ne 0) do begin
  79.       cpos = strpos(path, SEP)
  80.       if (cpos eq -1) then begin
  81.         item = path
  82.         path = ''
  83.       endif else begin
  84.         item = strmid(path, 0, cpos)
  85.         path = strmid(path, cpos+1, 32767)
  86.       endelse
  87.       if (is_vms) then begin
  88.         if (strmid(item, 0, 1) eq '@') then begin
  89.       item = strmid(item, 1, 32767)
  90.           spawn, 'LIBRARY/LIST/TEXT ' + item, tmp
  91.           if (n_elements(tmp) lt 9) then $
  92.              message, "Invalid Text Library", /traceback
  93.           tmp = tmp(8:*)        ; Skip the header. 9 is a magic #
  94.         endif else begin
  95.           tmp = findfile(item+'*.PRO')
  96.           for i = 0, n_elements(tmp)-1 do begin        ; Strip path and ext
  97.             tmp1 = strmid(tmp(i), strpos( tmp(i), ']')+1, 32767 )
  98.         tail = STRPOS( tmp1, '.PRO' )
  99.         tmp(i) = strmid( tmp1, 0 , tail )
  100.       endfor
  101.         endelse
  102.       endif else begin
  103.         if (!VERSION.OS EQ 'IRIX') then ls_com = '/bin/ls ' $
  104.                                    else ls_com = '/bin/ls -1 '
  105.         spawn, ls_com + item + '/*.pro', tmp
  106.         tmp = strupcase(tmp)
  107.         tail = STRPOS(tmp, '.PRO')
  108.         for i = 0, n_elements(tmp)-1 do begin        ; Strip path and ext
  109.       tmp1 = strmid(tmp(i), 0, tail(i))
  110.       j = STRPOS(tmp1, '/')
  111.           while (j ne -1) do begin
  112.         tmp1 = strmid(tmp1, j+1, 32767)
  113.         j = STRPOS(tmp1, '/')
  114.           endwhile
  115.       tmp(i) = tmp1
  116.         endfor
  117.       endelse
  118.       if (N_NAMES eq 0) then begin
  119.         names = tmp
  120.       endif else begin
  121.         names = [ names, tmp]
  122.       endelse
  123.       N_NAMES = N_NAMES + 1
  124.     endwhile
  125.  
  126.     names = names(uniq(names, sort(names)))
  127.   endif
  128.  
  129.   ; Fudge time. Different list lengths work best for OPEN LOOK and Motif
  130.   version = WIDGET_INFO(/VERSION)
  131.   if (version.style EQ 'OPEN LOOK') then n=22 else n = 30
  132.   return, WIDGET_LIST(parent, value=names, ysize=n)
  133.  
  134. end
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. pro xdl_update, name
  143. ; Update the display by running DOC_LIBRARY on NAME and updating
  144. ; the text widget to reflect the results. The status widget is
  145. ; used to keep the user informed of progress.
  146.  
  147.   common XDL_BLOCK, NAMES, N_NAMES, text_w, status_w
  148.  
  149.   WIDGET_CONTROL, status_w, set_value='Status: Please Wait', /HOURGLASS
  150.  
  151.   name = strlowcase(name)
  152.   is_vms = !version.os eq 'vms
  153.  
  154.   if (is_vms) then begin
  155.     ON_ERROR, 3
  156.     OFILE='userlib.doc'
  157.     DL_VMS, NAME, /FILE, /NOFILEMSG
  158.   endif else begin
  159.     OFILE='/tmp/idl_xdl.tmp'
  160.     DL_UNIX, NAME, print='cat > /tmp/idl_xdl.tmp'
  161.   endelse
  162.  
  163.   openr, unit, OFILE, /get_lun, /stream, /delete, err=err
  164.   if (err eq 0) then begin
  165.     tmp = fstat(unit)
  166.     text = bytarr(tmp.size)
  167.     readu, unit, text
  168.     free_lun, unit
  169.   endif else begin
  170.     text = 'Unable to locate routine: ' + strupcase(name)
  171.   endelse
  172.  
  173.   WIDGET_CONTROL, text_w, set_value = string(text)
  174.   WIDGET_CONTROL, status_w, set_value='Status: Ready'
  175.  
  176. end
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. pro xdl_event, ev
  185.  
  186.   common XDL_BLOCK, NAMES, N_NAMES, text_w, status_w
  187.  
  188.   case (tag_names(ev, /STRUCTURE_NAME)) of
  189.   "WIDGET_BUTTON": WIDGET_CONTROL, /DESTROY, ev.top
  190.   "WIDGET_LIST": begin
  191.     XDL_UPDATE, NAMES(ev.index)
  192.     end
  193.   endcase
  194.  
  195.  
  196. end
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. pro XDL, name, group=group
  205.  
  206.   common XDL_BLOCK, NAMES, N_NAMES, text_w, status_w
  207.  
  208.   on_error, 1        ; On error, return to main level
  209.  
  210.   if (!version.os EQ 'Win32') then message, $
  211.         'ERROR - XDL not supported under IDL for Windows'
  212.  
  213.   if (!version.os EQ 'MacOS') then message, $
  214.         'ERROR - XDL not supported under IDL for Macintosh'
  215.     
  216.   REQ_PRESENT = N_ELEMENTS(NAME) ne 0
  217.   if (REQ_PRESENT) then begin
  218.     temp = size(NAME)
  219.     if (temp(0) NE 0) then message, 'Argument must be scalar.'
  220.     if (temp(1) NE 7) then message, 'Argument must be of type string.'
  221.     if (STRLEN(STRCOMPRESS(NAME, /REMOVE_ALL)) eq 0) then REQ_PRESENT = 0
  222.   endif
  223.  
  224.   if (!D.FLAGS and 65536) NE 65536 then message, $
  225.         'ERROR - Current Device ' + !D.NAME + ' does not support widgets'
  226.   new_instance = not xregistered('XDL')
  227.   if (new_instance) then begin
  228.     base = WIDGET_BASE(title='XDL', /ROW)
  229.     do_announce = (WIDGET_INFO(/ACTIVE) eq 0) and (n_elements(names) eq 0)
  230.     if (do_announce) then $
  231.     junk = WIDGET_MESSAGE('Searching !PATH for routine names. This will take a few moments...')
  232.     cntl1 = WIDGET_BASE(base, /FRAME, /COLUMN, space=30)
  233.       pb_quit = WIDGET_BUTTON(value='Quit', cntl1)
  234.       status_w = WIDGET_LABEL(cntl1, value='Status: Please Wait', /frame)
  235.       geo = WIDGET_INFO(status_w, /GEOMETRY)
  236.       WIDGET_CONTROL, status_w, set_value='Status: Ready', $
  237.                   SCR_XSIZE=geo.scr_xsize
  238.       junk = WIDGET_BASE(cntl1, /frame, /COLUMN)
  239.         l = WIDGET_LABEL(junk, value='Library Routines')
  240.         list = xdl_list(junk)
  241.     text_w = WIDGET_TEXT(base, /SCROLL, xsize = 80, ysize=40)
  242.  
  243.     WIDGET_CONTROL, base, /REALIZE
  244.   endif
  245.  
  246.   if (REQ_PRESENT) then xdl_update, name
  247.  
  248.   if (new_instance) then $
  249.     XMANAGER, 'XDL', base, event_handler='XDL_EVENT', group=group
  250. end
  251.  
  252.